package com.soft.line.controller;

import com.soft.line.entity.AttachmentInfo;
import com.soft.line.service.AttachMentInfoService;
import com.soft.line.util.exception.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Api(description = "附件接口")
@Slf4j
@RestController
@RequestMapping("/attachment")
public class AttachmentController {

    @Autowired
    private AttachMentInfoService attachMentInfoService;

    @ApiOperation(value = "获取附件列表", notes = "获取附件列表")
    @GetMapping("/attachment/{attachmentType}/{id}")
    public CommonResult getAll(@PathVariable("attachmentType") String attachmentType,@PathVariable("id") Integer id){
        System.out.println("attachmentType:"+attachmentType);
        return CommonResult.success(attachMentInfoService.selectAll(attachmentType,id));
    }


    @ApiOperation(value = "删除附件", notes = "删除附件")
    @DeleteMapping("/attachment")
    public CommonResult delete(@RequestBody Map<String,Object> map){
        attachMentInfoService.delete(map);
        return CommonResult.success("删除成功");
    }

    @ApiOperation(value = "上传附件", notes = "上传附件")
    @PostMapping("/upload")
    public CommonResult upload(@RequestParam("file") MultipartFile uploadFile,
                               @RequestParam("type") String type,@RequestParam("cId")Integer cId){
        return CommonResult.success(attachMentInfoService.save(uploadFile,type,cId));
    }

}
